package com.scs.application.modules.base.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.base.entity.Location;
import com.scs.application.modules.base.entity.LocationLimitMatr;
import com.scs.application.modules.base.service.LocationLimitMatrService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 库位耗材范围 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/location/limit_matr")
public class LocationLimitMatrController extends CrudController<LocationLimitMatrService, LocationLimitMatr> {
    /**
     * 添加/更新数据
     */
    @Override
    @PostMapping("/save")
    public RestResult saveItem(@Valid @RequestBody LocationLimitMatr entity) {
        boolean isOk = service.saveOrUpdate(entity);
        if (!isOk) {
            return RestResult.error("数据保存失败");
        }
        return RestResult.ok("数据保存成功", entity);
    }

    @GetMapping("/getDefaultLocation")
    public RestResult getDefaultLocation(@RequestParam("matrId") String matrId,
                                         @RequestParam("warehouseId") String warehouseId, @RequestParam("packageUnit") String packageUnit) {
        Location location = service.getSuitLocation(warehouseId, matrId,packageUnit);
        return RestResult.ok("查询成功", location);
    }


    @GetMapping("/bindOrUnbind")
    synchronized public RestResult bindOrUnbind(String uniqueCode,String locationCode) {
        return service.bindOrUnbind(uniqueCode, locationCode);
    }

}
